<?php
// š
include_once('data.php');

if (isset($_GET['rev']) && isset($_GET['line'])) {
	$mysqli = new mysqli(CONNECT_HOST, CONNECT_USER, CONNECT_PASS, CONNECT_DB);
	$mysqli->query("SET NAMES 'utf8'");

	$sql = "select line_id, line_direction, line_order, stop_id, stop_platform, distance_time from linestops where line_id in (".$_GET['line'].") order by line_direction, line_order;";
	$result = $mysqli->query($sql);
	if (mysqli_num_rows($result) != 0) {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
		echo "<linedepartlist>\n";
		while ($row = $result->fetch_assoc()) {
			$sql = "select line_id, line_direction, stop_id, departure_time, schedule_type, exceptional_route_id, line_revision from linestopdepart where line_id=".$row['line_id']." and line_direction=".$row['line_direction']." and stop_id=".$row['stop_id']." and line_revision > ".$_GET['rev'].";";
			$result1 = $mysqli->query($sql);
			if (mysqli_num_rows($result1) != 0) {
				while ($row1 = $result1->fetch_assoc()) {
					echo "\t<departure line_id=\"".$row['line_id']."\" direction=\"".$row1["line_direction"]."\" stop_id=\"".$row1["stop_id"]."\">\n";
					echo "\t\t<departure_time>" . $row1["departure_time"] . "</departure_time>\n";
					echo "\t\t<schedule_type>" . $row1["schedule_type"] . "</schedule_type>\n";
					echo "\t\t<exceptional_route_id>" . $row1["exceptional_route_id"] . "</exceptional_route_id>\n";
					echo "\t\t<line_revision>" . $row1["line_revision"] . "</line_revision>\n";
					echo "\t</departure>\n";
				}
			}
		}
		echo "</linedepartlist>";
	} else {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<linedepartlist>\n</linedepartlist>";	
	}
}
?>